<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<% String path=request.getContextPath(); String basePath=request.getScheme()+ "://" + request.getServerName() + ":" + request.getServerPort() + path+ "/"; %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" >
<html  xmlns="http://www.w3.org/1999/xhtml"> 
<head>
<base href="<%=basePath%>">
<title>激活卡人员权限管理</title>
<%@ include file="/WEB-INF/jsp/common/common.jsp" %>
<script src="js/jquery.divbox.js" type="text/javascript"></script>
	<style>
		.power_btn, .role_btn {
			font-size: 12px;
			background: #ddd;
			/* color: #fff; */
			height: 20px;
			line-height: 20px;
		}
		.div_body {
			padding: 15px 20px;
			border-bottom: 1px solid #ddd;
			line-height: 30px;
		}
		.h_30 {
			height: 30px;
		}
		.red {
			color: red;
		}
	</style>
	<script type="text/javascript">
	// 新增页面 start
	function addPeople() {
		self.location.href="<%=path%>/cardPower/checkOrAdd";
	}
	// 新增页面 end
	// 查询页面 start
	function checkPeople() {
		if ($('.table_highlighter').length == 1) {
			var userid = $('.table_highlighter').children()[1].innerHTML
			self.location.href="<%=path%>/cardPower/checkOrAdd?userid=" + userid
		} else {
			$.message("error", "请选择一个用户！")
		}
	}
	// 新增页面 end
	// 查询列表 start
	function queryuserList(current) {
		var comName = $('#comName').val()
		var comCode = $('#comCode').val()
		var userCode = $('#userCode').val()
		var userName = $('#userName').val()
		// 查询
		queryuser({current: current, size: 10, comName: comName, comCode: comCode, userCode: userCode, userName: userName})
	}
	function queryuser(param) {
		$.openLoading();
 		$.ajax({
			url : "cardPower/queryuser",
			type : 'POST',
			async : true,
			dataType:'json',
			data: param,
			success : function(page) {
				$.closeLoading();
				var radioObj ="<input class='input_fxk' name='userRadio' type='radio' value=''>";
				var fieldNames = "userid@TDH,userCode,userComcode,userName,email,telephone,userPower@TDH";
				var lastColumnElement ="<input type='button' class='role_btn' value='角色' onClick='getRole(this)' /> <input type='button' class='power_btn' value='权限' onClick='getPower(this)' />";
				var tableContent = creatTable1(fieldNames, page, radioObj, lastColumnElement);
				var tableObj = $("#cardPowerTable");
				tableObj.find("tbody").remove();
				tableObj.append(tableContent);
				
				var strPage = creatChannelPage(page.current,6,page.maxPage,"78");
				var pageDIV = $("#cardPowerDIV");
				pageDIV[0].innerHTML="";
				pageDIV.append(strPage);
				bindradio();//点击单选按钮，该行高亮显示 
			}
		}) 
	}
	// 查询列表 end
	/* 多选按钮高亮 start */
    function bindradio(){
		$("input[name='userRadio']").click(function(){
			$("input[name='userRadio']").parent().parent().removeClass("table_highlighter");
			$(this).parent().parent().addClass("table_highlighter");
	   	});
    }
    /* 多选按钮高亮 end */
	// 初始化 start
	$(function init() {
		queryuserList('1')
	})

	// 初始化 end
	// 删除人员 start 
	function delUser() {
		if ($('.table_highlighter').length == 1) {
		$.dialog({
			type: "warn",//success,error
			content: "您确定要删除吗？",
			onOk: function() {
				var userid = $('.table_highlighter').children()[1].innerHTML
		    	var param = {userid: userid}
				$.openLoading();
		 		$.ajax({
					url : "cardPower/deluser",
					type : 'POST',
					async : true,
					dataType:'json',
					data: param,
					success : function(data) {
						$.closeLoading();
						if("success"==data.result&&""!=data.message){
							$.message("success", data.message);
							queryuserList($('.page_a_click').html())// 重新查询当前页码
						}
						if("fail"==data.result){
				    		$.message("error", "系统错误,请联系管理员");
				    	}
						if("error"==data.result&&""!=data.message){
				    		$.message("error", data.message);
				    	}
					}
				}) 
			}
		});
		}else{
			 $.message("error", "请选择一个用户！")
		}
    }
	// 删除人员 end
	// 获取角色 start
	function getRole(obj) {
		var userid = $(obj).parent().parent().children()[1].innerHTML
		var param = {userid: userid}
		$.ajax({
			url : "cardPower/getuserrole",
			type : 'POST',
			async : true,
			dataType:'json',
			data: param,
			success : function(data) {
				$.closeLoading();
				var str = ''
				var rolestr = ''
				$.each(data, function (i, v) {
					rolestr += v.roleName + ','
				})
				if (rolestr.length > 0) {
					str = '该用户有以下角色：<span class="red">' + rolestr.substring(0, rolestr.length-1) + '!</span>'
				} else {
					str = '该用户还没有配置角色！'
				}
				openDetailDiv(str)// 打开弹窗
			}
		}) 
	}
	// 获取角色 end
	// 获取权限 start 
	function getPower(obj) {
		var power = $(obj).parent().parent().children()[7].innerHTML
		var powerArr = power ? power.split('') : []
		var powerStrArr = ['卡申请', '卡复核', '卡核准', '卡延期', '退卡申请', '退卡复核']
		var str = ''
		var powerstr = ''
		$.each(powerArr, function (i, v) {
			if (v === '1') {
				powerstr += powerStrArr[i] + ','
			}
		})
		if (powerstr.length > 0) {
			str = '该用户有以下权限：<span class="red">' + powerstr.substring(0, powerstr.length-1) + '!</span>'
		} else {
			str = '该用户还没有配置权限！'
		}
		openDetailDiv(str)// 打开弹窗
	}
	// 获取权限 end
	// 显示权限详情弹窗 start
	function openDetailDiv(str) {
		$('.div_body').html(str)
		$('#detailDiv').OpenDiv();
	}
	// 显示权限详情弹窗 end
	// 关闭权限详情弹窗 start 
	function closeDetailDiv() {
		$('.role_div').html('')
		$('.power_div').html('')
		closeCurrentDIV('detailDiv')
	}
	//统一 关闭  窗口
	function closeCurrentDIV(obj){
		$("#"+obj).CloseDiv();
	}
	</script>
</head>
<body >
	<div class="current">
		<table class="current_table_1">
			<tbody>
				<tr class="f2">
		            <td>
		              <img src="./images/current_1.jpg">
		            </td>
		            <td class="current_table_1_td">
		              <img src="images/current_1.png">&nbsp;您现在的位置：&nbsp;
		                <span style=" color:#136bab; ">激活卡管理
		                	<span style="padding:0 5px; font-weight:bold; line-height:28px;">&gt;</span>
		                	激活卡人员管理
		            	</span>
		            </td>
		            <td><img src="./images/current_3.jpg"></td>
	        	</tr>
			</tbody>
		</table>
	</div>			
		
	<table class="table_02" id="table">
		<tr>
			<td>
				<table class="search_table">
					<tr class="h_30">
						<td width="25%" class="h_30">归属机构：
							<input name="comName" id="comName" type="text" class="input_text" maxlength="30" value="">
						</td>
						<td width="25%" class="h_30">机构代码：
							<input name="comCode" id="comCode" type="text" class="input_text" maxlength="30" value="">
						</td>
						<td width="25%" class="h_30">用户名：
							<input name="userCode" id="userCode" type="text" class="input_text" maxlength="30" value="">
						</td>
						<td width="25%" class="h_30">姓名：
							<input name="userName" id="userName" type="text" class="input_text" maxlength="30" value="">
						</td>
					</tr>
					<tr height="30px">
						<td height="30px" colspan="4" style="text-align: center;">
							<input type="button" class="input_button_1" id="searchBtn" value="查询" onClick="queryuserList(1)" />
							<input type="button" class="input_button_1" id="insertBtn" value="新增" onClick="addPeople()" />
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td>
				<table class="search_table">
					<tr class="h_30">
						<td class="h_30">
							<input type="button" class="input_button_1" id="" value="编辑" onClick="checkPeople()" />
							<input type="button" class="input_button_2" id="" value="删除权限" onClick="delUser()" />
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td>
				<div>
					<table id="cardPowerTable" class="content_table_1">
						<thead>
							<tr class="f1">
								<th style="width:3%;">选择</th>
								<th style="width:5%;">用户名</th>
								<th style="width:25%;">机构名称</th>
								<th style="width:6%;">姓名</th>
								<th style="width:8%;">邮件地址</th>
								<th style="width:8%;">用户电话</th>
								<th style="width:10%;">权限详情</th>
							</tr>
						</thead>
						<tbody>
						</tbody>
					</table>
				</div>
				
				<div id="cardPowerDIV" class="page"></div>
			</td>
		</tr>
	</table>
	<!-- 权限弹窗 start -->
	<div id="detailDiv" style="display: none; width: 40%;">
		<div class="div_body">
		</div>
		<div class="div_btn" align="center">
			<input class="input_button_3" type="button" onclick="closeDetailDiv()" value="确定">
		</div>
	</div>
	<!-- 权限弹窗 end -->
	<div id="Loading" style="display:none" align="center">
		<img src="./images/loading.gif" />
	</div>
</body>
</html>